//
//  TotalScore.m
//  HealthAsk
//
//  Created by liyuhang on 12-8-20.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "TotalScore.h"
#import "MainWin.h"


@implementation TotalScore
@synthesize  m_pHExamination;
+(CCScene *) scene:(HExamination*)exam
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	TotalScore *layer = [[[TotalScore alloc] InitwithHExam:exam] autorelease];
	
	// add layer as a child to scene
	[scene addChild: layer];
    
  	// return the scene
	return scene;
}
-(TotalScore*)InitwithHExam:(HExamination *)exam
{
    if( (self=[super init]) ) {
    self.m_pHExamination = exam;
    
    NSString * _writeCount = [NSString stringWithFormat:@"%d",[exam m_nWriteCount]];
    _writeCount = [NSString stringWithFormat:@"正确答对：%@",_writeCount];
    m_pLabelWriteCount = [CCLabelTTF labelWithString:_writeCount fontName:@"Marker Felt" fontSize:40];
    CGSize size = [[CCDirector sharedDirector] winSize];
    // position the label on the center of the screen
    m_pLabelWriteCount.position =  ccp( size.width/2, size.height/6  );
    [self addChild:m_pLabelWriteCount];
    
    [self createLabel:[exam m_nScore] pointX:size.width/2 pointY:3*size.height/6  title:@"得分" label:m_pLabelScore];
    [self createLabel:[exam m_nAnswerTime] pointX:size.width/2 pointY:5*size.height/6  title:@"答题时间" label:m_pLabelTime];
    [self scheduleUpdate];
    }
    [self scheduleOnce:@selector(makeTransition) delay:2];
    
    return self;
}

-(void)createLabel:(int)arg pointX:(int)pointx pointY:(int)pointy  title:(NSString *)title label:(CCLabelTTF*)label
{
    NSString * _writeCount = [NSString stringWithFormat:@"%d",arg];
    _writeCount = [NSString stringWithFormat:@"%@：%@",title,_writeCount];
    label = [CCLabelTTF labelWithString:_writeCount fontName:@"Marker Felt" fontSize:40];
    // position the label on the center of the screen
    label.position =  ccp(pointx,pointy);
    [self addChild:label];
}
-(void)dealloc
{
    [m_pHExamination dealloc];
    [super dealloc];
}
-(void)makeTransition
{
    self.isTouchEnabled = YES;
}
-(void)update:(ccTime)dely
{
    NSLog(@"sdfsdf");
}
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainWin scene] withColor:ccWHITE]];
}
@end
